/*$(document).ready(function(){
	// session超时跳转到登录页
	var searchStr = location.search; //获取Location对象的search属性值
	searchStr = searchStr.substr(1); //由于searchStr属性值包括“?”，所以除去该字符
	if(searchStr != ""){
		var searchs = searchStr.split("&");
		var timeout = searchs[0].split("=")
		if(timeout[0] == "timeout"){
			$("#loginMessage").html("登录超时,请重新登录！");
		}
	}
	
	// session超时 重新跳转到登录（iframe页面，整体跳转到登录页）
	if (window != top) {  
        top.location.href = location.href;  
    }  
});*/

//更换验证码
function chageValidateCode(){
	$("#validateCode").attr("src","images/code.jpg?t=" + Math.floor(Math.random() * ( 1000 + 1)));
}

function dealMatch(data){
	if(data["resultInfo"]==1){
		$("form").submit();
		if(document.getElementById("rmbUser").checked){
			 $.cookie("rmbUser", "true", { expires: 7 }); //存储一个带7天期限的cookie
	         $.cookie("username", $("#loginname").val(), { expires: 7 });
	         $.cookie("password", $("#pwd").val(), { expires: 7 });
		}else{
            $.cookie("rmbUser", "false", { expire: -1 });
            $.cookie("username", "", { expires: -1 });
            $.cookie("password", "", { expires: -1 });
	    }
	}else{
		$("#loginMessage").html(data["resultData"]);
		chageValidateCode();
	}
}



$(function(){
	$(".loginbody").css("height",650);
    $('.loginbox').css({'position':'absolute','left':($(document).width()-692)/2});
    $('.loginbox').css({'position':'absolute','top':($(window).height()-336)/2});
	$(window).resize(function(){  
		$(".loginbody").css("height",650);
	    $('.loginbox').css({'position':'absolute','left':($(window).width()-692)/2});
        $('.loginbox').css({'position':'absolute','top':($(window).height()-336)/2});
    })
	document.onkeydown = function (event) { 
		var e = event || window.event || arguments.callee.caller.arguments[0]; 
		if (e && e.keyCode == 13) { 
			$("#login_btn").click();
		}  
	}
    $("#login_btn").click(function(){
    	var name=$("#loginname").val();
    	var pwd=$("#pwd").val();
    	var code=$("#codetext").val();
		$("#loginname").css("border-color","#ccc");
		$("#pwd").css("border-color","#ccc");
		$("#codetext").css("border-color","#ccc");
    	if(name==""){
    		$("#loginMessage").html("用户名不能为空");
    		$("#loginname").css("border-color","red");
    	}else if(pwd==""){
    		$("#loginMessage").html("密码不能为空");
    		$("#pwd").css("border-color","red");
    	}else if(code==""){
    		$("#loginMessage").html("验证码不能为空");
    		$("#codetext").css("border-color","red");
    	}else{
    		var loginData = $("#loginForm").serialize();
    		
    		var msgResult = ajaxResult("get",false,"loginservlet.login.do",loginData);
    		if(msgResult.status == 'Failed'){
    			$("#loginMessage").html(msgResult.msg);
    		}else{
    			window.location.href = "home.jsp";
    		}
    	}
    })
    
	$("#loginname").focus(function(){
		$(this).css("border-color","#ccc");
	})
	$("#pwd").focus(function(){
		$(this).css("border-color","#ccc");
	})
	$("#codetext").focus(function(){
		$(this).css("border-color","#ccc");
	})
});
